package JavaImages;

import java.io.*;
import java.util.*;
import java.awt.image.*;
import javax.imageio.ImageWriter;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageInputStream;

/**
 *  Simple, non-functional ImageWriterSpi used to understand how 
 *  information regarding format name, suffices and mime types
 *  get passed to ImageIO static methods
 */
public class ch5v1ImageWriterSpi extends ImageWriterSpi {
    
    static final String[] suffixes = {"ch5", "CH5"};
    static final String[] names = {"ch5"};
    static final String[] MIMETypes = {"image/ch5" };    

    static final String version = "0.50";

    static final String writerCN = "ch5.imageio.plugins.ch5v1ImageWriter"; 

    static final String vendorName = "Company Name";
    static final String[] rdrSpiNames={"ch5.imageio.ch5v1ImageReaderSpi"};

    static final boolean supportsStandardStreamMetadataFormat = false;
    static final String nativeStreamMetadataFormatName = null;
    static final String nativeStreamMetadataFormatClassName = null;
    static final String[] extraStreamMetadataFormatNames = null;
    static final String[] extraStreamMetadataFormatClassNames = null;


    static final boolean supportsStandardImageMetadataFormat = false;
    static final String nativeImageMetadataFormatName = null;
    static final String nativeImageMetadataFormatClassName = null;
    static final String[] extraImageMetadataFormatNames = null;
    static final String[] extraImageMetadataFormatClassNames = null;

    public ch5v1ImageWriterSpi() {
	super(vendorName, 
	      version,
	      names,
	      suffixes,
	      MIMETypes,
	      writerCN, //writer class name
	      STANDARD_OUTPUT_TYPE,
	      rdrSpiNames, //reader spi names
	      supportsStandardStreamMetadataFormat,
	      nativeStreamMetadataFormatName,
	      nativeStreamMetadataFormatClassName,
	      extraStreamMetadataFormatNames,
	      extraStreamMetadataFormatClassNames,
	      supportsStandardImageMetadataFormat,
	      nativeImageMetadataFormatName,
	      nativeImageMetadataFormatClassName,
	      extraImageMetadataFormatNames,
	      extraImageMetadataFormatClassNames);
    }

    public String getDescription(Locale locale) {
	return "Demo ch5 image writer, version " + version;
    }


    /**
     * We haven't created the corresponding ImageWriter class yet,
     * so we'll just return null for now.  
     */
    public ImageWriter createWriterInstance(Object extension) {
	return new ch5v1ImageWriter(this);
    }

    /**
     * This method gets called when an application wants to see if 
     * the corresponding ImageWriter can encode an image with
     * a ColorModel and SampleModel specified by the ImageTypeSpecifier.
     * For this example, we will only advertise that we can encode
     * gray scale images with 8 bit pixels.
     */
    public boolean canEncodeImage(ImageTypeSpecifier its) {
	if (its.getBufferedImageType() == BufferedImage.TYPE_BYTE_GRAY)
	    return true;
	else 
	    return false;
    }

    /**
     * This method gets called when the set of file suffices is 
     * requested by the ImageIO's getImageWritersBySuffix method 
     * It doesn't need to be redefined here, but is done for
     * illustrative purposes
     */
    public String[] getFileSuffixes() {
	return super.getFileSuffixes();
    }

    /**
     * This method gets called when the set of file mime types is 
     * requested by the ImageIO's getImageWritersByMIMEType method 
     * It doesn't need to be redefined here, but is done for
     * illustrative purposes
     */
    public String[] getMIMETypes() {
	return super.getMIMETypes();
    }

    /**
     * This method gets called when the set of format names is 
     * requested by the ImageIO's getImageWritersByFormatName method 
     * It doesn't need to be redefined here, but is done for
     * illustrative purposes
     */
    public String[] getFormatNames() {
	return super.getFormatNames();
    }
}
